package com.gec.anan.driver.service.impl;

import com.alibaba.nacos.common.codec.Base64;
import com.gec.anan.common.constant.RedisConstant;
import com.gec.anan.common.execption.AnanException;
import com.gec.anan.common.result.Result;
import com.gec.anan.common.result.ResultCodeEnum;
import com.gec.anan.driver.client.OcrFeignClient;
import com.gec.anan.driver.service.OcrService;
import com.gec.anan.model.vo.driver.DriverLicenseOcrVo;
import com.gec.anan.model.vo.driver.IdCardOcrVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

@Slf4j
@Service
@SuppressWarnings({"unchecked", "rawtypes"})
public class OcrServiceImpl implements OcrService {
    @Autowired
    private OcrFeignClient client;

    @Override
    public IdCardOcrVo idCardOcr(MultipartFile multipartFile) {
        Result<IdCardOcrVo> idCardOcrVoResult = client.idCardOcr(multipartFile);
        if (idCardOcrVoResult==null){
            throw new AnanException(idCardOcrVoResult.getCode(), idCardOcrVoResult.getMessage());
        }
        if(idCardOcrVoResult.getData()==null){
            throw new AnanException(ResultCodeEnum.IMAGE_AUDITION_FAIL );
        }
        return idCardOcrVoResult.getData();
    }

    @Override
    public DriverLicenseOcrVo driverLicenseOcr(MultipartFile multipartFile) {
        Result<DriverLicenseOcrVo> driverLicenseOcrVoResult = client.driverLicenseOcr(multipartFile);
        if(driverLicenseOcrVoResult==null){
            throw new AnanException(driverLicenseOcrVoResult.getCode(), driverLicenseOcrVoResult.getMessage());
        }

        if(driverLicenseOcrVoResult.getData()==null){
            throw new AnanException(ResultCodeEnum.IMAGE_AUDITION_FAIL);
        }
        return driverLicenseOcrVoResult.getData();
    }
}
